<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/11
 * Time: 14:01
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\model\mysql;

use app\common\lib\Status;

class System extends Base
{
    /**
     * @param array $data
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSystemByData(array $data = []): bool
    {
        //查询是否存在 存在则更新 不存在则添加
        $row = $this->getSystemById();
        if(!empty($row)) {
            return $row->save($data);
        }else{
            return $this->save($data);
        }
    }

    /**
     * @return System|array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSystemById()
    {
        return $this->where('status',Status::mysql_normal)->find();
    }
}